import akka.actor.typed.ActorRef;
import akka.actor.typed.Behavior;
import akka.actor.typed.javadsl.AbstractBehavior;
import akka.actor.typed.javadsl.ActorContext;
import akka.actor.typed.javadsl.Behaviors;
import akka.actor.typed.javadsl.Receive;

public class TestKit extends AbstractBehavior<String> {

    private TestKit(ActorContext<String> context) {
        super(context);
    }

    static Behavior<String> create() {
        return Behaviors.setup(TestKit::new);
    }

    @Override
    public Receive<String> createReceive() {
        return newReceiveBuilder()
                .onMessageEquals("startStop", this::startStop)
                .onMessageEquals("failHandling", this::failHandling).build();
    }

    private Behavior<String> startStop() {
        ActorRef<String> first = getContext().spawn(StartStopActor1.create(), "first");
        first.tell("stop");
        return this;
    }

    private Behavior<String> failHandling() {
        ActorRef<String> supervisingActor = getContext().spawn(SupervisingActor.create(), "supervising-actor");
        supervisingActor.tell("failChild");
        return this;
    }
}
